// index.js
import Toast from '../../miniprogram/miniprogram_npm/@vant/weapp/toast/toast';
const request=require('../../util/request.js')
const navBarHeight = wx.getSystemInfoSync().statusBarHeight + 44;
Page({
  data: {
    navBarHeight:navBarHeight,
    customer:{},
    projects:[],
    account:{},
    all:[],
    tabIndex:0,
    field:"",
    accounts:[],
    taplock:false,
    longtap: false
  },
  setTabIndex(e){
    console.log(e)
    this.setData({
      tabIndex:e.currentTarget.dataset.index
    })
  },
  goPage(event){
    // console.log(event);
    if(event.currentTarget.dataset.pageurl=="/pages/register/register"){
      Toast('暂未开放注册~');
    }

    wx.navigateTo({
      url: event.currentTarget.dataset.pageurl,
    })
  },
  testshow(){
    console.log(this.data.account)
  },
  getAccounts(){
    var that = this;
    request.requestAjax('company/accounts_meet_ex',{},"加载中",function(res){
        if(res.status==200){
            that.setData({
              all:res.data.all,
              accounts:res.data.accounts
            });
            return false;
        }else{
          wx.showToast({
            title: '请求失败',
            icon:"none"
          })
        }
  
    },function(res){
      wx.showToast({
        title: '请求失败',
        icon:"none"
      })
    });
  },
  onLoad(options){
    if(options.field!=undefined){
      this.setData({
        field:options.field
      })
    }
  },
  onReady(){
    this.getAccounts();

  },
  onSelect(e){
    
    var account = this.data.accounts[e.currentTarget.dataset.index][e.currentTarget.dataset.i];

    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    // console.log(account)
    prevPage.setData({
      [this.data.field]:account
    })
    wx.navigateBack();
  },
  goPage(event){
    console.log(event);
    if(event.currentTarget.dataset.pageurl=="/pages/register/register"){
      Toast('暂未开放注册~');
      return false;
    }

    wx.navigateTo({
      url: event.currentTarget.dataset.pageurl,
    })
  },
})
